<!-- 选择零件号 -->
<template>
  <div id="dialog-container">
    <el-button @click="choose">选择零件号</el-button>
    <el-dialog v-dialogDrag :title="'选择零件号'" append-to-body :visible.sync="dialogVisible" :close-on-click-modal="false" width="680px">
      <el-form :inline="true" label-width="90px" size="small">
        <el-form-item label="零件号：">
          <el-input v-model="partNumber"></el-input>
        </el-form-item>
        <el-form-item label="零件图号：">
          <el-input v-model="partGraphNumber"></el-input>
        </el-form-item>
        <el-form-item label="零件名称：">
          <el-input v-model="partName"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click='choose'>查询</el-button>
        </el-form-item>
        <el-form-item>
            <el-button size="mini" @click='clearForm'>清除</el-button>
        </el-form-item>
      </el-form>
      <div style="float: left;padding-left: 20px;font-size: 15px;color: #666;padding-top: 6px;">
         共 <span style="color: red;">{{totalElements}}</span> 条数据
      </div>
      <el-table ref="multipleTable" @row-click="clickRow" :data="tableData"  highlight-current-row >
        <!-- <el-table-column type="selection" width="50" align="center"></el-table-column> -->
        <el-table-column type="index" label="序号" width="50" align="center"></el-table-column> 
        <el-table-column prop="partNumber" label="零件号" width="" align="center"></el-table-column>
        <el-table-column prop="partGraphNumber" label="零件图号" width="" align="center"></el-table-column>
        <el-table-column prop="partName" label="零件名称" align="center"></el-table-column>
      </el-table>
      <!-- <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitChoose">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div> -->
      <el-row type="flex" justify="center">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="pageSizeArr"
          :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageTotal"></el-pagination>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
  import {
    getPartList
  } from 'service/task';
  export default {
    data() {
      return {
        dialogVisible: false,
        partGraphNumber: '',
        partName: '',
        tableData: [],
        selectedVal: '',
        formData: {

        },
      currentPage: 1,
      pageSizeArr: [10, 20, 50, 100],
      pageSize: 10,
      pageTotal: 0,
      page: 0,
      isShowDevice: false,
      isShowModify: false,
      modifyId: "",
      totalElements: 0
      }
    },
    props: {
        partNumber: {
          type: String
        },
    },
    updated() {

    },
    
    methods: {
      clickRow(val){
        this.$emit("partVal", val);
        this.dialogVisible = false;
      },
      handleCurrentChange(val) {
      this.currentPage = val;
      this.choose();
      },
      clearForm() {
      this.partGraphNumber = '';
      this.partName = '';
      this.partNumber = '';
      this.choose();
      },
      handleSizeChange(val){
        this.pageSize = val;
        this.choose();
      },
      choose() {
        // this.formData.partNumber = "";
        // this.formData.partDrawingNumber = "";
        // this.formData.partDrawingNumber = "";
        this.dialogVisible = true;
        this.formData['partGraphNumber'] = this.partGraphNumber;
        this.formData['partName'] = this.partName;
        this.formData['partNumber'] = this.partNumber;
        this.dialogVisible = true;
        this.formData['pageNumber'] = this.currentPage;
        this.formData['pageSize'] = this.pageSize;
        this.formData['sort'] = "";
        this.formData['order'] = "";
         this.loading = true;
        getPartList(this.formData).then(res => {
          this.tableData = res.data.result.content;
          this.pageSize = res.data.result.pageable.pageSize;
          this.pageTotal = res.data.result.totalElements;
          this.totalElements = res.data.result.totalElements;
           this.loading = false;
        })
      },
      handleSelectionChange(val) {
        if (val.length > 1) {
          this.$refs.multipleTable.clearSelection();
          this.$alert('只能选择一条数据！', '提示', {
            type: 'error'
          })
        } else if (val.length == 1) {
          this.selectedVal = val[0];
        }
      },
      // 确定
      submitChoose() {
        console.log(9)
        if (this.selectedVal === "") {
          this.$alert('请选择一条数据！', '提示', {
            type: 'warning'
          })
        } else {
          this.$emit("partVal", this.selectedVal);
          this.dialogVisible = false;
        }
      }
    }
  }
</script>
